﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace program1
{
    public class DataParser
    {
        private Form1 mainForm;

        public DataParser(Form1 form)
        {
            mainForm = form;
        }

        public void FindPhoneNumbers(string htmlContent, string sourceUrl)
        {
            // 使用正则表达式查找电话号码
            string phoneNumberPattern = @"((\d{3}[-.\s]??\d{3}[-.\s]??\d{4})|(\(\d{3}\)[-.\s]?\d{3}[-.\s]?\d{4}))";
            MatchCollection matches = Regex.Matches(htmlContent, phoneNumberPattern);

            List<string> phoneNumbers = new List<string>();

            foreach (Match match in matches)
            {
                string phoneNumber = match.Value;
                phoneNumbers.Add(phoneNumber);

                // 记录电话号码所属的URL
                mainForm.UpdateCrawledUrlsList(sourceUrl);
            }

            mainForm.DisplayPhoneNumbers(phoneNumbers.ToArray());
        }
    }
}
